/**
 * @param {number[]} nums
 * @return {number}
 */
var longestConsecutive = function(nums) {
    if(nums.length===0){
        return 0
    }
    let numSet=new Set(nums)
    let res=1
    for(let s of numSet){
        if(numSet.has(s-1)){
            continue
        }
        let j=s+1
        let tempRes=1
        while(numSet.has(j)){
            j++
            tempRes++
        }
        res=res>tempRes?res:tempRes
    }
    return res
};

let nums = [100,4,200,1,3,2]
console.log(longestConsecutive(nums));